{include file="common/_header-css"}
{include file="common/_jQuery"}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">题库管理</a>
        <a>
          <cite>题库管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="layui-inline layui-show-xs-block">
                        <a href="{:url('question/option')}" class="layui-btn">返回选择页面</a>
                    </div>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加选择题','{:url(\'question_add\')}?type=1&department_id={$department.id}&department_name={$department.name}',800,600)"><i class="layui-icon"></i>添加选择题</button>
                    <button class="layui-btn" onclick="xadmin.open('添加判断题','{:url(\'question_add\')}?type=2&department_id={$department.id}&department_name={$department.name}',800,600)"><i class="layui-icon"></i>添加判断题</button>
                    <button type="button" class="layui-btn" name="excel" id="optionExcel"><i class="layui-icon">&#xe67c;</i>上传选择题Excel</button>
                    <button type="button" class="layui-btn" name="excel" id="opinionExcel"><i class="layui-icon">&#xe67c;</i>上传判断题Excel</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
<!--                            <th>ID</th>-->
                            <th>题号</th>
                            <th>题目</th>
                            <!--<th>image</th>-->
                            <th>答案</th>
                            <th>正确答案</th>
                            <th>题型</th>
                            <th>属于部门</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="vo"}
                        <tr>
<!--                            <td>{$vo.id}</td>-->
                            <th>{$vo.sort}</th>
                            <td>{$vo.title}</td>
                            <!--<td>null</td>-->
                            <td>
                                {if $vo.type == 1}
                                <p>A.{$vo.answers.0}</p>
                                <p>B.{$vo.answers.1}</p>
                                <p>C.{$vo.answers.2}</p>
                                <p>D.{$vo.answers.3}</p>
                                {else /}
                                判断题没有选项
                                {/if}
                            </td>
                            <td>
                                {if $vo.type == 1}
                                {if $vo.answer == 1}A{elseif $vo.answer == 2}B{elseif $vo.answer == 2}C{else /}D{/if}
                                {else /}
                                {if $vo.answer == 0}正确{else /}错误{/if}
                                {/if}
                            </td>
                            <td>{if $vo.type == 1}选择题{else /}判断题{/if}</td>
                            <td>{$vo.department_id}</td>
                            <td class="td-manage">
                                <a title="删除" onclick="member_del(this,'{$vo.id}')" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i>
                                </a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <div>
                            {$list|raw}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });


    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.post('{:url(\'question/delete\')}',{id:id,type:3},function (res) {
                if (res.code == 200) {
                    $(obj).parents("tr").remove();
                    layer.msg(res.msg,{icon:1,time:1000});
                }else{
                    layer.msg(res.msg,{icon:5,time:500});
                }
            });
        });
    }
</script>

<script>
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例  -- 选择题
        upload.render({
            elem: '#optionExcel' //绑定元素
            ,url: '{:url(\'admin/question/upload_excel\')}?department_id={$department.id}&type=1' //上传接口
            ,done: function(res){
                console.log(res);
                if (res.code == 200){
                    layer.msg(res.msg,{icon:1,time:500},function () {
                        location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:5,time:1000});
                }

            }
            ,error: function(){
                //请求异常回调
            }
            ,accept: 'file'
            ,size: 50
        });

        // -- 判断题
        upload.render({
            elem: '#opinionExcel' //绑定元素
            ,url: '{:url(\'admin/question/upload_excel\')}?department_id={$department.id}&type=2' //上传接口
            ,done: function(res){
                if (res.code == 200){
                    layer.msg(res.msg,{icon:1,time:500},function () {
                        location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:5,time:1000});
                }

            }
            ,error: function(){
                //请求异常回调
            }
            ,accept: 'file'
            ,size: 50
        });
    });
</script>
</body>

</html>